<%--
  Created by IntelliJ IDEA.
  User: 13241
  Date: 2022/2/13
  Time: 13:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
  <head>
    <title>分页查询</title>
    <style>
      .search{
        text-align: center;
      }
      table {
        margin: 0 auto;
        border-collapse: collapse;
      }

      table, td, th {
        border: 1px solid black;
      }
    </style>
  </head>
  <body>
    <table cellspacing="0">
     <%-- 表头--%>
      <tr>
        <th>编号</th>
        <th>名称</th>
        <th>作者</th>
        <th>出版日期</th>
        <th>价格</th>
        <th>类型编号</th>
        <th>封面</th>
        <th>文档类型</th>
        <th>下载</th>
      </tr>
       <%-- 表体--%>
      <c:forEach items="${requestScope.pagebean.list}" var="book">
        <tr>
          <td>${book.id}</td>
          <td>${book.name}</td>
          <td>${book.author}</td>
          <td>
            <fmt:formatDate value="${book.publish}" pattern="yyyy-MM-dd"/>
          </td>
          <td>${book.price}</td>
          <td>${book.typeid}</td>
          <td>book.cover</td>
          <td>book.doctype</td>
          <td>
            <a href="#">删除</a>
          </td>
        </tr>
      </c:forEach>
      <%--页码控制--%>
      <tr align="center">
        <td colspan="9">
          <a href="javascript:void(0)" onclick="changePage(${requestScope.pagebean.currentPage-1})">上一页</a>
          <c:forEach begin="1" end="${requestScope.pagebean.totalPage}" var="pagenum">
            <c:choose>
              <c:when test="${pagenum eq requestScope.pagebean.currentPage}">
                [${pagenum}]
              </c:when>
              <c:otherwise>
                ${pagenum}
              </c:otherwise>
            </c:choose>
          </c:forEach>
          <a href="javascript:void(0)" onclick="changePage(${requestScope.pagebean.currentPage+1})">下一页</a>
          &nbsp;&nbsp;&nbsp;尾页&nbsp;&nbsp;&nbsp;
          每页
          <input id="pageSize" style="width: 40px" type="text" value="${requestScope.pagebean.pageSize}">
          条
          &nbsp;&nbsp;&nbsp;
          当前第
          ${requestScope.pagebean.currentPage}
          页
          &nbsp;&nbsp;&nbsp;
          共
          ${requestScope.pagebean.totalPage}
          页
          &nbsp;&nbsp;&nbsp;
          共
          ${requestScope.pagebean.totalSize}
          条记录
          &nbsp;&nbsp;&nbsp;
        </td>
      </tr>

    </table>
  <script>
    function changePage(currentPage) {
      if (currentPage<1){
        alert("已经是第1页了");
        return
      }else if (currentPage>${requestScope.pagebean.totalPage}){
        alert("已经是最后一页了")
        return;
      }else {
        var pageSize = document.getElementById("pageSize");
        window.location.href="http://localhost:8010/pageDemo_war_exploded/bookservlet.do?currentPage="+currentPage+"&pageSize="+pageSize.value;
      }
    }
  </script>

  </body>
</html>
